package com.sise.cn.api.common.impl;

import com.sise.cn.api.common.po.Product;
import com.sise.cn.api.common.service.ProductService;
import com.sise.cn.dao.base.BaseMapper;
import com.sise.cn.dao.base.TableSpace;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 龚秀峰
 * @version 1.0
 * @date 2020/6/14 12:11
 * 商品的默认实现接口
 */
@Service
@Slf4j
@ConditionalOnMissingBean(ProductService.class)
public class ProductServiceImpl implements ProductService {
    @Resource
    private BaseMapper baseMapper;

    @Override
    public Product getProductById(Long id) {
        final Product product = new Product();
        product.setId(id);
        return baseMapper.select(product, Product.class);
    }

    @Override
    public Long saveProduct(Product product) {
        return baseMapper.insertAndGetId(product);
    }

    @Override
    public void updateProduct(Product product) {
        baseMapper.update(product);
    }

    @Override
    public List<Product> getProductByCondition(TableSpace tableSpace) {
        return baseMapper.selectList(tableSpace, Product.class);
    }

    @Override
    public void deleteProductById(Long id) {
        final Product product = new Product();
        product.setId(id);
        baseMapper.delete(product);
    }
}
